package leetcode100;

public class lc027 {
    public static void main(String[] args) {
        int[] height = new int[] {1,8,6,2,5,4,8,3,7};
        int maxArea = new lc027().maxArea(height);
        System.out.println("maxArea = " + maxArea);
    }

    public int maxArea(int[] height) {
        int maxArea=0;
        int curArea = 0;

        int left=0;
        int right = height.length-1;

        while(left<right) {
            curArea = Math.min(height[left],height[right])*(right-left);
            maxArea = Math.max(curArea,maxArea);
            if (height[left]<height[right]) {
                left++;
            } else {
                right--;
            }
        }

        return maxArea;
    }
}
